// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>
#include <turbo/log/logging.h>

namespace cantor::unresolved {
    class UnresolvedDispatchExpr;
    class UnresolvedTableOption;
    class UnresolvedTableName;
    class UnresolvedColumnDef;
    class UnresolvedAssignment;
    class UnresolvedConstraint;
    class UnresolvedPartitionRange;
    class UnresolvedWhereClause;

    class UnresolvedAlterTableSpec : public UnresolvedVisitor<UnresolvedAlterTableSpec> {
    public:
        static constexpr const cantor::pb::ast::ExprNodeType TYPE = cantor::pb::ast::ExprNodeType::ENT_ALTER_SEPC;

        UnresolvedAlterTableSpec(const cantor::pb::ast::AlterTableSpec &node) : instance(node) {
        }

        ~UnresolvedAlterTableSpec() override = default;

        const pb::Location &location_impl() const {
            return instance.location();
        }

        const pb::Status &error_status_impl() const {
            return instance.status();
        }

        cantor::pb::ast::AlterSpecType spec_type() const {
            return instance.spec_type();
        }

        std::string spec_type_str() const {
            return cantor::pb::ast::AlterSpecType_Name(instance.spec_type());
        }

        std::string_view column_name() const {
            return instance.column_name();
        }

        size_t table_option_size() const {
            return instance.table_options_size();
        }

        bool has_new_table_name() const {
            return instance.has_new_table_name();
        }

        UnresolvedTableName new_table_name() const;

        std::vector<UnresolvedTableOption> table_options() const;

        UnresolvedTableOption table_option(size_t index) const;

        size_t new_column_size() const {
            return instance.new_columns_size();
        }

        std::vector<UnresolvedColumnDef> new_column_defs() const;

        UnresolvedColumnDef new_column_def(size_t index) const;

        size_t set_list_size() const {
            return instance.set_list_size();
        }

        std::vector<UnresolvedAssignment> new_assignments() const;

        UnresolvedAssignment new_assignment(size_t index) const;

        bool has_where() const {
            return instance.has_where();
        }

        UnresolvedWhereClause where_clause() const;

        size_t new_constrain_size() const {
            return instance.new_constraints_size();
        }

        bool has_index_name() const {
            return instance.has_index_name();
        }

        std::string_view index_name() const {
            if (!instance.has_index_name()) {
                return std::string_view();
            }
            return instance.index_name();
        }

        bool has_resource_tag() const {
            return instance.has_resource_tag();
        }

        std::string_view resource_tag() const {
            if (!instance.has_resource_tag()) {
                return std::string_view();
            }
            return instance.resource_tag();
        }

        bool force() const {
            return instance.force();
        }

        bool is_virtual_index() const {
            return instance.is_virtual_index();
        }

        bool is_unique_indicator() const {
            return instance.is_unique_indicator();
        }

        bool has_partition_range() const {
            return instance.has_partition_range();
        }

        UnresolvedPartitionRange partition_range() const;

        std::vector<UnresolvedConstraint> new_constraints() const;

        UnresolvedConstraint new_constraint(size_t index) const;

        const cantor::pb::ast::AlterTableSpec &instance;
    };
} // namespace cantor::unresolved
